package com.spotmanger.project.modular.spottable.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spotmanger.project.common.core.utils.DataResult;
import com.spotmanger.project.modular.spottable.entity.SpottableRepairedNewEntity;
import com.spotmanger.project.modular.spottable.service.SpottableRepairedNewService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 复垦/待复垦图斑的基础信息表。
 *
 * @author leihao
 * @email 1321451088@qq.com
 * @date 2021-09-20 10:53:23
 */
@Controller
@RequestMapping("/")
public class SpottableRepairedNewController {
    @Autowired
    private SpottableRepairedNewService spottableRepairedNewService;


    /**
     * 跳转到页面
     */
    @GetMapping("/index/repairedNew")
    public String spottableRepairedNew() {
        return "spottable/spottablerepairednew/list";
    }

    @ApiOperation(value = "新增")
    @PostMapping("repairedNew/add")
    @RequiresPermissions("repairedNew:add")
    @ResponseBody
    public DataResult add(@RequestBody SpottableRepairedNewEntity spottableRepairedNew) {
        spottableRepairedNewService.save(spottableRepairedNew);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("repairedNew/delete")
    @RequiresPermissions("repairedNew:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids) {
        spottableRepairedNewService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("repairedNew/update")
    @RequiresPermissions("repairedNew:update")
    @ResponseBody
    public DataResult update(@RequestBody SpottableRepairedNewEntity spottableRepairedNew) {
        spottableRepairedNewService.updateById(spottableRepairedNew);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("repairedNew/listByPage")
    @RequiresPermissions("repairedNew:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SpottableRepairedNewEntity spottableRepairedNew) {
        Page page = new Page(spottableRepairedNew.getPage(), spottableRepairedNew.getLimit());
        LambdaQueryWrapper<SpottableRepairedNewEntity> queryWrapper = spottableRepairedNewService.searchByTBBH(spottableRepairedNew);
        IPage<SpottableRepairedNewEntity> iPage = spottableRepairedNewService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
